package com.niit.pys.service;


import com.niit.pys.repository.CommRepository;
import com.niit.pys.repository.UserRepository;
import com.niit.pys.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private CommRepository commRepository;
    @Override
    public void addUser(User user) {
        userRepository.save(user);
    }

    @Override
    public void updateUser(User user) {
        userRepository.save(user);
    }

    @Override
    public void deleteUser(User user) {
        userRepository.delete(user);
    }

    @Override
    public void deleteUserById(Integer uid) {
        userRepository.deleteById(uid);
    }

    @Override
    public List<User> findAllUsers() {
        return (List<User>) userRepository.findAll();
    }

    @Override
    public List<User> findUserByName(String userName) {
        return (List<User>) userRepository.findUserByName(userName);
    }

    @Override
    public void addAllUsers(List<User> users) {
        userRepository.saveAll(users);
    }
}
